package com.qf.controller;

import com.qf.pojo.Project;
import com.qf.service.ProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ProjectController
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/7 15:03
 * @Version 1.0
 **/
@Controller
@RequestMapping("project")
@Slf4j
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Project> list = projectService.findAll();
        System.out.println(list);
        model.addAttribute("projects",list);
        return "/project/list";

    }
    @RequestMapping("delete")
    private String deleteProject(int pid){
        int i = projectService.deleteProject(pid);
        return "redirect:/project/findAll";
    }

    @PostMapping("add")
    @ResponseBody
    private String addProject(@RequestBody Project project){
        boolean b = projectService.addProject(project);
       if (b){
           return "redirect:/project/findAll";
       }else {
           return "project/error";
       }
    }
}
